package com.none.staff.view.adapter

import android.content.Context
import android.graphics.drawable.Drawable
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.none.staff.R

class NewsRoomAdapter(private var context: Context?) : RecyclerView.Adapter<NewsRoomAdapter.NewsHolder>() {

    override fun onCreateViewHolder(p0: ViewGroup, p1: Int): NewsHolder {
        val view: View = LayoutInflater.from(context).inflate(R.layout.news_room_rv_item_layout, p0, false)
        val newsHolder = NewsHolder(view)
        return newsHolder
    }

    override fun getItemCount(): Int {
        return 30
    }

    override fun onBindViewHolder(p0: NewsHolder, p1: Int) {
        Glide.with(context).load(R.mipmap.h).into(p0.imageView)
        tvSetDrawableSize(p0.tvLike!!, R.mipmap.unlike)
        tvSetDrawableSize(p0.tvBrowse!!, R.mipmap.nobrowse)
    }

    private fun tvSetDrawableSize(tv: TextView, res: Int) {
        val drawable: Drawable = context?.resources?.getDrawable(res)!!
        drawable.setBounds(0, 0, 40, 40)  //width即为你需要设置的图片宽度，height即为你设置的图片的高度
        tv.compoundDrawablePadding = 6   //设置图片和text之间的间距
        tv.setCompoundDrawables(drawable, null, null, null)
    }

    class NewsHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        var imageView: ImageView? = null
        var tvTitle: TextView? = null
        var tvInduction: TextView? = null
        var tvPostDate: TextView? = null
        var tvLike: TextView? = null
        var tvBrowse: TextView? = null

        init {
            imageView = itemView.findViewById(R.id.img_rv_news_thumbnail)
            tvTitle = itemView.findViewById(R.id.tv_rv_news_title)
            tvInduction = itemView.findViewById(R.id.tv_rv_news_induction)
            tvPostDate = itemView.findViewById(R.id.tv_rv_news_post_date)
            tvLike = itemView.findViewById(R.id.tv_rv_news_like)
            tvBrowse = itemView.findViewById(R.id.tv_rv_news_browse)
        }

    }
    
}